Certified Java Programmer Mock Exam


Question 1


Which of these words belong to the set of java keywords?

a. clause
b. loop
c. expression
d. overrides
e. statement
f. assertion
g. validate
h. exception
i. cast
j. None of the Above

Question 2


Which of these words belong to the set of java keywords?

a. exit
b. strictfp
c. enum
d. super
e. abort
f. event
g. goto
h. native
i. exception
j. None of the Above

Question 3


Which of these words belong to the set of java keywords?

a. exit
b. boolean
c. short
d. include
e. const
f. sizeof
g. instanceof
h. register
i. goto
j. None of the Above

Question 4


class A {
  public static void main (String[] args) {
    // Insert code here.
  }
}

Which of the following lines can be inserted at the specified location without generating a compile-time error?

a. String a = 'a';
b. String b = 'abc';
c. String c = '\u0041';
d. String d = '\uabcd';
e. None of the Above

Question 5


class Basics {
  private static int x;
  protected static int y;
  public static int z;
  public static void main (String[] args) {
    System.out.println(x+y+z);
  }
}

What is the result of attempting to compile and run the above program?

a. Prints nothing.
b. Prints an undefined value.
c. Prints: null
d. Prints: 0
e. Run time Exception
f. Compiler Error
g. None of the Above

Question 6


1.  class Green {
2.    public static void main (String[] args) {
3.      char a = '\b';
4.      char b = '\c';
5.      char c = '\d';
6.      char d = '\f';
7.      char e = '\l';
8.      char f = '\n';
9.      char g = '\r';
10.     char h = '\t';
11.     char i = '\\';
12.     char j = '\"';
13.     char k = '\'';
14.   }
15. }

What is the result of attempting to compile and run the program?

a. Compiler error at line 3.
b. Compiler error at line 4.
c. Compiler error at line 5.
d. Compiler error at line 6.
e. Compiler error at line 7.
f. Compiler error at line 8.
g. Compiler error at line 9.
h. Compiler error at line 10.
i. Compiler error at line 11.
j. Compiler error at line 12.
k. Compiler error at line 13.
l. None of the Above

Question 7


Which of these words belong to the set of java keywords?

a. transient
b. serializable
c. runnable
d. run
e. volatile
f. externalizable
g. cloneable
h. None of the Above

Question 8


Which of these words belong to the set of java keywords?

a. byte
b. short
c. int
d. long
e. decimal
f. int64
g. float
h. single
i. double
j. boolean
k. char
l. unsigned
m. array
n. string
o. None of the Above

Question 9


class A {
  public static void main (String[] args) {
    float a = 1;            // 1
    float b = 1L;           // 2
    float c = 1F;           // 3
    float d = 1.0;          // 4
  }
}

A compile-time error is generated at which lines?

a. 1
b. 2
c. 3
d. 4
e. None of the Above

Question 10


class A {
  public static void main (String[] args) {
    String a = "abcd";          // 1
    String b = "'\u0041'";      // 2
    String c = "\u0041";        // 3
    String d = "\uabcd";        // 4
    System.out.print(a+b+c+d);  // 5
  }
}

A compile-time error is generated at which lines?

a. 1
b. 2
c. 3
d. 4
e. 5
f. None of the Above

Question 11


class A {
  public static void main(String args[]) {
    System.out.print(Integer.toBinaryString(Byte.MAX_VALUE)+",");
    System.out.print(Integer.toOctalString(Byte.MAX_VALUE)+",");
    System.out.print(Integer.toString(Byte.MAX_VALUE)+",");
    System.out.print(Integer.toHexString(Byte.MAX_VALUE));
  }
}

What is the result of attempting to compile and run the program?

a. Prints: 1111111,177,127,7f
b. Prints: 11111111,377,256,ff
c. Compiler Error
d. Runtime Error
e. None of the Above

Question 12


class A {
  public static void main(String args[]) {
    byte x = 85;
    System.out.print(Integer.toBinaryString(x)+",");
    System.out.print(Integer.toOctalString(x)+",");
    System.out.print(Integer.toString(x)+",");
    System.out.print(Integer.toHexString(x));
  }
}

What is the result of attempting to compile and run the program?

a. Prints: 11111111,377,85,ff
b. Prints: 1010101,125,85,55
c. Compiler Error
d. Runtime Error
e. None of the Above

Question 13


class Orange {
  public static void main (String[] args) {
    char c = '\u000a'; // '\u000a' = Linefeed
    System.out.print("ABC" + c);
  }
}

What is the result of attempting to compile and run the program?

a. Prints: ABC
b. Prints: ABCc
c. Prints: ABC10
d. Prints: ABCa
e. Prints: ABC0x000a
f. Compiler error.
g. Runtime error.
h. None of the Above

Question 14


class A {
  public static void main (String[] args) {
    // Insert code here.
  }
}

Which of the following lines can be inserted at the specified location without generating a compile-time error?

a. char a = 0x0041;
b. char b = '\u0041';
c. char c = 0101;
d. char d = -1;
e. char e = (char)-1;
f. None of the Above

Question 15


class B {
  public static void main(String args[]) {
    System.out.print(Integer.toHexString(Integer.MIN_VALUE)+",");
    System.out.print(Integer.toHexString(Integer.MAX_VALUE));
  }
}

What is the result of attempting to compile and run the program?

a. Prints: 0000,ffff
b. Prints: 00000000,ffffffff
c. Prints: 7fff,8000
d. Prints: 8000,7fff
e. Prints: 7fffffff,80000000
f. Prints: 80000000,7fffffff
g. Compiler Error
h. Runtime Error
i. None of the Above

Question 16


class X {
  public static void main(String[] args) {
    int i = 0;
    while (i++ < args.length) {
      System.out.print(args[i]);
    }
  }
}

Assume the above main method is invoked using the following
command line.

java X A B C D E F 

What is the result of attempting to compile and run the program using the specified command line?

a. Prints: ABCDE
b. Prints: BCDEF
c. Prints: ABCDEF
d. Compile-time error
e. Run-time exception
f. None of the Above

Question 17


1. class Violet {
2.   int x;
3.   public static void main(String[] args) {
4.     int y;
5.     System.out.print("x="+x);
6.     System.out.print(", y="+y);
7.   }
8. }

What is the result of attempting to compile and run the above program?

a. Compiler error at line 1.
b. Compiler error at line 2.
c. Compiler error at line 3.
d. Compiler error at line 4.
e. Compiler error at line 5.
f. Compiler error at line 6.
g. Runtime Exception
h. None of the Above

Question 18


class Black {
  static byte a;
  static short b;
  static char c;
  static int d;
  static long e;
  static String s;
  public static void main(String[] args) {
    System.out.println(a+b+c+d+e+s);
  }
}

What is the result of attempting to compile and run the above program?

a. Prints: 00000null
b. Prints: 00000
c. Prints: 0null
d. Prints: 0
e. Prints: null
f. Compiler Error.
g. Runtime Exception.
h. None of the Above.

Question 19


class E {
  static byte a = (byte)127;
  static byte b = (byte)128;
  static byte c = (byte)255;
  static byte d = (byte)256;
  public static void main(String args[]) {
    System.out.print(a + " " + b + " " + c + " " + d);
  }
}

What is the result of attempting to compile and run the above program?

a. Prints: 127 128 255 256
b. Prints: 127 128 255 0
c. Prints: 127 -1 -127 0
d. Prints: 127 -128 -1 0
e. Runtime Exception
f. Compiler Error
g. None of the Above


Copyright © 2002, Dan Chisholm
All rights reserved.
1